/* samplesim.ado --- 
 * 
 * Filename: samplesim.ado
 * Author: Arzheimer & Evans
 * 
 */

/* Commentary: 
 * Helper program to test how far B/B' are biased away from
 * zero in typical settings
 * 
 */

/* Change log:
 * 
 * 
 */

/* Code: */


program define samplesim , eclass
version 12
	syntax , n(numlist) vector(numlist)
	drop _all
	qui set obs `n'
* Put commas into numlist	
	local cvector = subinstr("`vector'"," ",",",.)
* Convert to Stata-Matrix
	matrix vector = `cvector'
* Sample from multinomial
* First, rescale vector to sum to unity
	mata: probvector = st_matrix("vector")
	mata: probvector = probvector / sum(probvector)
	mata: multinomial = rdiscrete(`n',1,probvector)
	getmata party=multinomial
	surveybias party,popvalues(`cvector')
	matrix bs = e(b)
	matrix bs = bs[1,"B:"]
	ereturn clear
	ereturn post bs
end



/* samplesim.ado ends here */
